package name.as3.frameworkTestSupport.manager
{
import flash.net.SharedObject;

import name.as3.cmdFrameworks.manager.AbstractManager;
import name.as3.frameworkTest.commands.OnLoginOKCommand;
import name.as3.frameworkTest.commands.OnNeedCreateCommand;
import name.as3.frameworkTest.commands.OnReadLastUserCommand;
import name.as3.frameworkTest.enums.CommandTestType;
import name.as3.frameworkTestSupport.ui.controls.TestAlert;

public class SharedObjectManager extends AbstractManager
{
	/**
	 *
	 */
	public static const UserName:String = "UserName";
	/**
	 *
	 */
	public static const Flag:String = "Flag";
	/**
	 *
	 */
	private var m_blNewUser:Boolean;
	private var m_so:SharedObject;
	/**
	 *
	 */
	public function SharedObjectManager()
	{
		super();
	}
//==================================================================================================
// public
//==================================================================================================
	public function requestLogin(strName:String):void
	{
		if (strName)
		{
			var so:SharedObject = SharedObject.getLocal(UserName);
			so.data[UserName] = strName;
			so.flush();
			m_so = SharedObject.getLocal("usr_" + strName);
			if (undefined == m_so.data[Flag])
			{
				m_so.data[Flag] = true;
				m_so.flush();
				m_blNewUser = true;
				facade.invokeCommand(CommandTestType.OnNeedCreate, OnNeedCreateCommand);
			}
			else
			{
				facade.invokeCommand(CommandTestType.OnLoginOK, OnLoginOKCommand);
			}
		}
		else
		{
			TestAlert(sgs()).show("用户名不能为空!");
		}
	}
	public function getLastUserName():void
	{
		var so:SharedObject = SharedObject.getLocal(UserName);
		if (undefined != so.data[UserName])
		{
			var str:String = so.data[UserName];
			this.facade.invokeCommand(CommandTestType.OnReadLastUser, OnReadLastUserCommand, str);
		}
	}
}
}